#pragma once
#include "Person.h"
#include "ContainerList.h"
#include <fstream>

class PersonList : public ContainerList<Person>
{
public:

	PersonList(void)
	{
	}

	~PersonList(void)
	{
	}

	void SaveToFile( string filename )
	{
		ofstream fout;

		try
		{
			fout.open( filename );
			for( auto &s : (*this) )
			{
				fout << s.info;
			}
			fout.close();
		}
		catch( exception e )
		{
			cerr << "Exception " << filename << endl;
			cerr << e.what() << endl;
		}
	}

	void ReadFromFile( string filename )
	{
		string str, strRow;
		ifstream fin;

		try
		{
			fin.open( filename );
			
			while( getline( fin, strRow ) )
			{
				istringstream iss( strRow );
				Person temp;

				iss >> temp;

				this->Add(temp);
			}
		}
		catch( exception e )
		{
			cerr << "Exception " << filename << endl;
			cerr << e.what() << endl;
		}
	}

};

